﻿<Window x:Class="MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:NamaAlert="clr-namespace:co9320"
    Title="" Height="350" Width="400" MinHeight="140" MinWidth="290" Icon="/NamaAlert;component/MainWindow.ico">

    <Window.CommandBindings>
        <CommandBinding Command="{x:Static NamaAlert:MainWindow.AddStationsCommand}" Executed="AddStationsCommand_Executed" CanExecute="ForDataGridRowsCommand_CanExecute" />
        <CommandBinding Command="{x:Static NamaAlert:MainWindow.DeleteStationsCommand}" Executed="DeleteStationsCommand_Executed" CanExecute="ForDataGridRowsCommand_CanExecute" />
        <CommandBinding Command="{x:Static NamaAlert:MainWindow.OpenUrisCommand}" Executed="OpenUrisCommand_Executed" CanExecute="ForDataGridRowsCommand_CanExecute" />
        <CommandBinding Command="{x:Static NamaAlert:MainWindow.CopyUriCommand}" Executed="CopyUriCommand_Executed" CanExecute="ForOnlyDataGridRowCommand_CanExecute" />
    </Window.CommandBindings>

    <Window.DataContext>
        <NamaAlert:MainWindowDataContext />
    </Window.DataContext>

    <Window.Resources>
        <NamaAlert:LiveProgramListViewStyleSelector x:Key="LiveProgramListViewStyleSelector"/>
        <NamaAlert:RecentAirdateConverter x:Key="RecentAirdateConverter" />
        <NamaAlert:MemberOnlyConverter x:Key="MemberOnlyConverter" />
        <NamaAlert:OnAirConverter x:Key="OnAirConverter" />

        <Style x:Key="ImageButtonBaseStyle" TargetType="{x:Type ButtonBase}">
            <Setter Property="OverridesDefaultStyle" Value="True"/>
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="Cursor" Value="Hand"/>
            <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
            <Setter Property="HorizontalContentAlignment" Value="Center"/>
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Setter Property="Padding" Value="0"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <ContentPresenter Name="Presenter" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" RecognizesAccessKey="True" RenderTransformOrigin="0.5,0.5"/>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsPressed" Value="True">
                                <Setter Property="RenderTransform" TargetName="Presenter">
                                    <Setter.Value>
                                        <TranslateTransform X="1" Y="1"/>
                                    </Setter.Value>
                                </Setter>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style x:Key="ImageButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource ImageButtonBaseStyle}"/>


        <ContextMenu x:Key="ProgramsRowContextMenu">
            <MenuItem Header="生放送のページへ移動" Command="{x:Static NamaAlert:MainWindow.OpenUrisCommand}" CommandParameter="program" />
            <MenuItem Header="URLをコピー" Command="{x:Static NamaAlert:MainWindow.CopyUriCommand}" CommandParameter="program" />
            <Separator />
            <MenuItem Header="通知対象に追加" Command="{x:Static NamaAlert:MainWindow.AddStationsCommand}" />
        </ContextMenu>

        <ContextMenu x:Key="StationsRowContextMenu">
            <MenuItem Header="生放送のページへ移動" Command="{x:Static NamaAlert:MainWindow.OpenUrisCommand}" IsEnabled="{Binding Path=IsOnAir}" CommandParameter="liveprogram" />
            <MenuItem Header="放送局のページへ移動" Command="{x:Static NamaAlert:MainWindow.OpenUrisCommand}" CommandParameter="station" />
            <MenuItem Header="生放送のURLをコピー" Command="{x:Static NamaAlert:MainWindow.CopyUriCommand}" IsEnabled="{Binding Path=IsOnAir}" CommandParameter="liveprogram" />
            <MenuItem Header="放送局のURLをコピー" Command="{x:Static NamaAlert:MainWindow.CopyUriCommand}" CommandParameter="station" />
            <Separator />
            <MenuItem Header="削除" Command="{x:Static NamaAlert:MainWindow.DeleteStationsCommand}" />
        </ContextMenu>

        <Style x:Key="StretchListViewItem" TargetType="ListViewItem">
            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
            <Setter Property="Padding" Value="1 2 1 2" />
            <Setter Property="ContextMenu" Value="{StaticResource ProgramsRowContextMenu}" />
        </Style>

        <!--<DataTemplate x:Key="FirstCell">
            <StackPanel Orientation="Horizontal" VerticalAlignment="Center" >
                <CheckBox IsChecked="{Binding Path=IsSelected, Mode=TwoWay}" />
            </StackPanel>
        </DataTemplate>-->
        
        <DataTemplate x:Key="CommentCountCell">
            <TextBlock Text="{Binding Path=CommentCount}" HorizontalAlignment="Right"/>
        </DataTemplate>
        <DataTemplate x:Key="VisitorCountCell">
            <TextBlock Text="{Binding Path=VisitorCount}" HorizontalAlignment="Right"/>
        </DataTemplate>

        <DataTemplate x:Key="ColumnHeaderSortedAscendingTemplate">
            <DockPanel>
                <TextBlock HorizontalAlignment="Center" Text="{Binding}"/>
                <Path x:Name="arrow"
           StrokeThickness = "1"                      
           Fill            = "gray"
           Data            = "M 5,10 L 15,10 L 10,5 L 5,10"/>
            </DockPanel>
        </DataTemplate>
        <DataTemplate x:Key="ColumnHeaderSortedDescendingTemplate">
            <DockPanel>
                <TextBlock HorizontalAlignment="Center" Text="{Binding}"/>
                <Path x:Name="arrow"
              StrokeThickness = "1"                      
              Fill            = "gray"
              Data            = "M 5,5 L 10,10 L 15,5 L 5,5"/>
            </DockPanel>
        </DataTemplate>
    </Window.Resources>
    
    <Grid >
        <TabControl>
            <TabItem Height="22"
                Header="{Binding Path=LiveProgramList.Count}" HeaderStringFormat="生放送一覧({0})">
                <Grid>
                    <NamaAlert:SortableListView 
                        ItemsSource="{Binding Path=LiveProgramList}"                         
                        MouseDoubleClick="LiveProgramListView_MouseDoubleClick"
                        ItemContainerStyleSelector="{StaticResource LiveProgramListViewStyleSelector}"
                        x:Name="LiveProgramListView">
                            
                            <NamaAlert:SortableListView.View>
                            <GridView>

                                <!--<NamaAlert:SortableGridViewColumn 
                                    CellTemplate="{StaticResource FirstCell}" 
                                    SortPropertyName="IsSelected"
                                    Width="30"/>-->
                                
                                <NamaAlert:SortableGridViewColumn Header="タイトル" 
                                    Width="{Binding Path=UserSettings.ProgramListViewTitleHeaderWidth, Mode=TwoWay}"
                                    DisplayMemberBinding="{Binding Path=Title}" 
                                    SortPropertyName="Title" />
                                <NamaAlert:SortableGridViewColumn Header="コミュニティ" 
                                    Width="{Binding Path=UserSettings.ProgramListViewCommunityHeaderWidth, Mode=TwoWay}"
                                    DisplayMemberBinding="{Binding Path=Community.Name}"
                                    SortPropertyName="Community.Name" />
                                <NamaAlert:SortableGridViewColumn 
                                    Header="開始時間"
                                    Width="{Binding Path=UserSettings.ProgramListViewStartDateTimeHeaderWidth, Mode=TwoWay}"
                                    DisplayMemberBinding="{Binding Path=StartDateTime, StringFormat=HH:mm}"
                                    SortPropertyName="StartDateTime" 
                                    IsDefaultSortColumn="True"
                                    DefaultSortDirection="Descending" />
                                <NamaAlert:SortableGridViewColumn Header="来場者数"
                                    Width="{Binding Path=UserSettings.ProgramListViewVisitorCountHeaderWidth, Mode=TwoWay}"
                                    CellTemplate="{StaticResource VisitorCountCell}"
                                    SortPropertyName="VisitorCount" />
                                <NamaAlert:SortableGridViewColumn Header="コメ数" 
                                    Width="{Binding Path=UserSettings.ProgramListViewCommentCountHeaderWidth, Mode=TwoWay}"
                                    CellTemplate="{StaticResource CommentCountCell}"
                                    SortPropertyName="CommentCount" />
                                <NamaAlert:SortableGridViewColumn Header="公開" 
                                    Width="{Binding Path=UserSettings.ProgramListViewMemberOnlyHeaderWidth, Mode=TwoWay}"
                                    DisplayMemberBinding="{Binding Path=IsMemberOnly, Converter={StaticResource MemberOnlyConverter}}"
                                    SortPropertyName="IsMemberOnly" />
                                <NamaAlert:SortableGridViewColumn Header="詳細" 
                                    Width="{Binding Path=UserSettings.ProgramListViewContentHeaderWidth, Mode=TwoWay}"
                                    DisplayMemberBinding="{Binding Path=Content}"
                                    SortPropertyName="Content" />
                                
                            </GridView>
                        </NamaAlert:SortableListView.View>
                    </NamaAlert:SortableListView>
                    <!--<StackPanel Grid.Row="1" Orientation="Horizontal" Margin="0 8 0 0" HorizontalAlignment="Right">
                        <Button Content="更新" Width="80" Margin="5 0" Click="ReloadButton_Click" Name="ReloadButton" IsEnabled="False" />
                        <Button Content="登録" Width="80" Command="{x:Static NamaAlert:MainWindow.SubscribeCommand}" />
                    </StackPanel>-->
                </Grid>

            </TabItem>
            <TabItem Header="{Binding Path=CommunityList.Count}" HeaderStringFormat="登録コミュニティ({0})"  Name="CommunityTabItem">
                <Grid>
                    <NamaAlert:SortableListView ItemsSource="{Binding Path=CommunityList}" 
                          MouseDoubleClick="CommunitiesListView_MouseDoubleClick"
                          x:Name="CommunitiesListView"
                          
                              >
                        <NamaAlert:SortableListView.ItemContainerStyle>
                            <Style TargetType="ListViewItem">
                                <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                                <Setter Property="Padding" Value="1 2 1 2" />
                                <Setter Property="ContextMenu" Value="{StaticResource StationsRowContextMenu}" />
                            </Style>
                        </NamaAlert:SortableListView.ItemContainerStyle>
                            <NamaAlert:SortableListView.View>
                            <GridView >
                                <!--<GridViewColumn  
                                    CellTemplate="{StaticResource FirstCell}" 
                                    Width="30">
                                    <CheckBox Click="CommunityListViewColumnCheckBox_Click" />
                                </GridViewColumn>-->

                                <NamaAlert:SortableGridViewColumn 
                                    Header="On Air" 
                                    Width="{Binding Path=UserSettings.CommunityListViewOnAirHeaderWidth, Mode=TwoWay}"
                                    SortPropertyName="IsOnAir"
                                    DisplayMemberBinding="{Binding Path=IsOnAir, Converter={StaticResource OnAirConverter}}" />
                                <NamaAlert:SortableGridViewColumn 
                                    Header="コミュニティ名" 
                                    Width="{Binding Path=UserSettings.CommunityListViewNameHeaderWidth, Mode=TwoWay}"
                                    DisplayMemberBinding="{Binding Path=Name}"
                                    SortPropertyName="Name" />
                                <NamaAlert:SortableGridViewColumn 
                                    Header="最近の放送日時" 
                                    Width="{Binding Path=UserSettings.CommunityListViewAirateHeaderWidth, Mode=TwoWay}"
                                    DisplayMemberBinding="{Binding Path=RecentAirdate, Converter={StaticResource RecentAirdateConverter}}"
                                    SortPropertyName="RecentAirdate" />
                            </GridView>
                        </NamaAlert:SortableListView.View>
                    </NamaAlert:SortableListView>
                    <!--<StackPanel Grid.Row="1" Orientation="Horizontal" Margin="0 8 0 0" HorizontalAlignment="Right">
                        <Button Content="削除" Width="80" Command="{x:Static NamaAlert:MainWindow.DeleteCommand}" />
                    </StackPanel>-->

                </Grid>
            </TabItem>
        </TabControl>
        <!--<Button HorizontalAlignment="Left" Padding="0" Margin="5,0,0,5" 
                VerticalAlignment="Bottom" Width="80" Height="26" 
                Content="設定" 
                Click="SettingsButton_Click" />-->

        <Button Padding="0" Margin="4" VerticalAlignment="Top" HorizontalAlignment="Right"
                                    Style="{StaticResource ImageButtonStyle}"
                Click="SettingsButton_Click"
                ToolTipService.ToolTip="設定">
            <Image Margin="0" Source="gear.png" Stretch="None" />
        </Button>

    </Grid>
</Window>
